package service.impl;

import constant.Constant;
import dao.CategoryMapper;
import dao.RoomMapper;
import entity.Category;
import entity.Room;
import framework.bean.factory.ObjectFactory;
import framework.bean.factory.annotation.Component;
import service.RoomService;

import java.util.Date;
import java.util.List;

@Component("roomServiceTarget")
public class RoomServiceImpl implements RoomService {
    @Override
    public List<Category> findCategories() {

        CategoryMapper categoryMapper= (CategoryMapper) ObjectFactory.getObject("categoryMapper");

        return categoryMapper.selectAll();
    }

    @Override
    public List<Room> findAvailable(Integer categoryId, Integer resideType, Date startDate, Date endDate) {


        RoomMapper roomMapper= (RoomMapper) ObjectFactory.getObject("roomMapper");

        List<Room> rooms=null;

        //整间预定
        if(Constant.ResideType.RESIDE_TYPE_ROOM.equals(resideType)){
            rooms=roomMapper.selectAvailableRooms(categoryId,startDate,endDate);
        }

        //床位预定
        if(Constant.ResideType.RESIDE_TYPE_BED.equals(resideType)){
            rooms=roomMapper.selectAvailableBeds(categoryId,startDate,endDate);
        }


        return rooms;
    }
}
